<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>理财列表</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
    <script type="text/javascript">
        function closeWin(){
            api.closeWin({
            });

            var n = api.pageParam.index;
            if (n == null) {
                n = 0;
            }
            page = n;
        };
    </script>
</head>
<body>
    <!-- <header class="aui-bar aui-bar-nav">投资理财</header> -->
    <!-- 智投专区 -->
    <div class="licai-list-zhitou">
        <div class="licai-list-zhitou-t">
            随意享 <span></span><span id="num3" class="money"></span><span>随存随取</span>
        </div>
        <div id="list3"></div>

        <div class="licai-list-zhitou-t">
            智能理财 <span id="num" class="money"></span><span>7x24h可购</span><span>红包奖励</span>
        </div>
        <div id="list"></div>

        <div class="licai-list-zhitou-t" id="you" style="display: none;">
            优质债权 <span></span><span id="num2" class="money"></span>
        </div>
        <div class="index-list">
            <ul>
                <div id="list2"></div>
            </ul>
        </div>
    </div>
</body>

<script type="text/template" id="template3">

    <ul>
        {{~it:value:index}}
        <li onclick="licai_yuebao({{=value.id}})" tapmode>
            <div class="licai-list-zhitou-l aui-pull-left">
                <p>{{=value.rate}}<i>%</i></p>
                预期年化利率
            </div>
            <div class="licai-list-zhitou-m aui-pull-left">
                <!-- <p id="end_date">{{=value.end_date}}</p> -->
                <p id="end_date">T+1</p>
                周期
            </div>
            <div class="licai-list-zhitou-r aui-pull-right">
                <p>立即抢购</p>
                无限制
            </div>
        </li>
        {{~}}
    </ul>

</script>

<script type="text/template" id="template">

    <ul>
        {{~it:value:index}}
        <li onclick="licai_zhitou({{=value.id}})" tapmode>
            <div class="licai-list-zhitou-l aui-pull-left">
                <p>{{=value.rate}}<i>%</i></p>
                预期年化利率
            </div>
            <div class="licai-list-zhitou-m aui-pull-left">
                <p>{{=value.time_limit}}个月</p>
                期限
            </div>
            <div class="licai-list-zhitou-r aui-pull-right">
                <p>立即抢购</p>
                剩余<span class="money">{{=value.borrow_amount}}</span>元
            </div>
        </li>
        {{~}}
    </ul>

</script>
<script type="text/template" id="template2">
    {{~it:value:index}}
    <li  {{? value.deal_status!=1}}class="off"{{?}} onclick="licai_sanbiao('{{=value.id}}')" tapmode>
        <div class="t">{{=value.name}} {{=value.deal_sn}}</div>{{? value.repay_time==1}}<i>新手</i>{{?}}
        <div class="m">
            <div class="m-l">{{=value.rate}}<i>%</i></div>
            <div class="m-r"><span>{{=value.repay_time}}</span>个月<i></i>{{? value.loantype==0}}等额本息{{?? value.loantype==1}}每月付息，到期还本{{?? value.loantype==2}}到期还本息{{?? value.loantype==3}}先息后本{{??}}{{?}}</div>
        </div>
        <div class="j">
            <div class="aui-progress">
                <div class="aui-progress-bar" style="width:{{=value.progress_point}}%;"></div>
            </div>
            <p>{{=value.progress_point}}%</p>
        </div>
        <div class="d">
            <!-- <i class="fa fa-exclamation-circle"></i>借款人可能提前还款 --><span>元</span><span class="money2">{{=value.surplusmoney}}</span><span>剩余</span>
        </div>
        {{? value.deal_status==1}}{{?? value.deal_status==2}}<div class="licai-icon"><img src="image/licai-icon-1.png" alt=""></div>{{?? value.deal_status==3}}<div class="licai-icon"><img src="image/licai-icon-2.png" alt=""></div>{{?? value.deal_status==4}}<div class="licai-icon"><img src="image/licai-icon-3.png" alt=""></div>{{?? value.deal_status==5}}<div class="licai-icon"><img src="image/licai-icon-4.png" alt=""></div>{{??}}{{?}}
    </li>
    {{~}}
</script>

<script type="text/javascript">
    apiready = function(){

        load_list();
        addObserver();
        down_refresh();

    };

    function licai_yuebao(id){

        var delay = 0;
        if(api.systemType != 'ios'){
            // delay = 300;
        }

        var end_date = $('#end_date').text();

        api.openWin({
            name: 'licai_yuebao',
            url: './licai-yuebao.html',
            pageParam: {
                id: id,
                end_date: end_date
            }
        });

    };

    function licai_zhitou(id){

        var delay = 0;
        if(api.systemType != 'ios'){
            // delay = 300;
        }

        api.openWin({
            name: 'licai_zhitou',
            url: './licai-zhitou.html',
            pageParam: {
                id: id
            }
        });

    };

    function licai_sanbiao(id){

        var delay = 0;
        if(api.systemType != 'ios'){
            // delay = 300;
        }

        api.openWin({
            name: 'licai_sanbiao',
            url: './licai-sanbiao.html',
            pageParam: {
                id: id
            }
        });
    };

    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){

            load_list(true);
        });
    }

    // 加载列表
    function load_list(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        if (n) {
            page += 1;
        }else {
            page = 1;
        }

        api.ajax({
            url: webAddress+'/index.php?ctl=app_deal&act=deal_list&page='+page,
            method: 'get',
        },function(ret, err){
            // alert($api.jsonToStr(ret));
            if (ret) {
                if (ret.status == 0) {
                    alert(ret.info);
                }else if (ret.status == 1) {
                    // api.hideProgress();
                    if (page == 1) {
                      //  alert(ret.licai.list.length);
                      for (var i = 0; i < ret.licai.list.length; i++) {
                        ret.licai.list[i].borrow_amount = outputmoney(ret.licai.list[i].borrow_amount);
                    }
                    updateList(ret.licai.list, ret.licai.min_money);

                    api.ajax({
                        url: 'http://www.big-wealth.com/index.php?ctl=app_deal&act=config',
                        method: 'post',
                    },function(ret2, err){
            // alert($api.jsonToStr(ret2));

                        if (ret2) {

                            var isHide = ret2.status;
                            if (api.systemType != 'ios' || isHide == 1) {

                                updateList2(ret.deal.list, page, ret.deal.min_money);
                                $("#you").show();
                            }
                        } else {

                        }
                    });

                    updateList3(ret.balance.list, ret.balance.min_money);
                }
                for (var i = 0; i < ret.deal.list.length; i++) {
                    ret.deal.list[i].surplusmoney = outputmoney(ret.deal.list[i].surplusmoney);
                    ret.deal.list[i].progress_point = ret.deal.list[i].progress_point.toFixed(2);
                }

                // api.refreshHeaderLoadDone();
            }else if (ret.status == 2){

                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
            }
            api.refreshHeaderLoadDone();
            api.hideProgress();
        } else {
            alert(err.msg);
            api.refreshHeaderLoadDone();
            api.hideProgress();
        }
    });
    }

    // 下拉刷新
    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err){
            page = 1;
            load_list();
        });
    }

    // doT
    function updateList3(data, num){

        var template = $api.byId('template3');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list3');
        $api.html(list, html);
        document.getElementById('num3').innerHTML = outputmoney(num).substr(0, outputmoney(num).length-3)+'元起投';
    }

    function updateList(data, num){

        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);
        // $(".money").each(function(){
        //     // alert($(this).text());
        //     var tmp = outputmoney($(this).text());
        //     $(this).text(tmp);
        // });
        document.getElementById('num').innerHTML = outputmoney(num).substr(0, outputmoney(num).length-3)+'元起投';
    }

    function updateList2(data, page, num){

        var template = $api.byId('template2');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list2');

        if (page == 1) {
            $api.html(list, html);
            // $(".money2").each(function(){
            //     // alert($(this).text());
            //     var tmp = outputmoney($(this).text());
            //     $(this).text(tmp);
            // });
            document.getElementById('num2').innerHTML = outputmoney(num).substr(0, outputmoney(num).length-3)+'元起投';
        }else {

            if (!data) {
                api.toast({
                  msg: '没有更多了',
                  duration: 2000,
                  location: 'bottom'
              });
                return;
            }
            $api.append(list, html);
        }
        api.parseTapmode();
    }

</script>
</html>
